/*
	LayoutGroup.cpp
	(c)2000 Palestar Inc, Richard Lyle
*/

#define INTERFACE_DLL
#include "Debug/Assert.h"
#include "Interface/GameDocument.h"
#include "Interface/LayoutGroup.h"
#include "Interface/ButtonContact.h"

//----------------------------------------------------------------------------

template<class T>
T * GetChild( NodeWindow * pWindow, int i )
{
	if ( i < pWindow->childCount() )
		return dynamic_cast<T *>( pWindow->child(i) );

	return NULL;
}

//----------------------------------------------------------------------------

IMPLEMENT_FACTORY( LayoutGroup, WindowLayout );
REGISTER_FACTORY_KEY( LayoutGroup, 4380230593850490619 );

LayoutGroup::LayoutGroup()
{}

//----------------------------------------------------------------------------

void LayoutGroup::onActivate()
{
	m_Update = 1.0f;
	detachAllNodes();
}

void LayoutGroup::onDeactivate()
{
	detachAllNodes();
	m_Update = 0.0f;
}

void LayoutGroup::onUpdate( float t )
{
	WindowLayout::onUpdate( t );

	GameDocument * pDoc = dynamic_cast<GameDocument *>( document() );
	ASSERT( pDoc );
	NounShip * pShip = pDoc->ship();
	if (! pShip )
		return;

	/*
	m_Update += t;
	if ( m_Update > 1.0f )
	{
		m_Update = 0.0f;

		int count = 0;
		for(int i=0;i<pDoc->groupCount();i++)
		{
			NounShip * pShip = pDoc->group( i );
			if ( pShip != NULL )
			{
				ButtonContact * pButton = GetChild<ButtonContact>( this, i );
				if ( pButton != NULL )
					pButton->setNoun( pShip );
				else
					new ButtonContact( this, pShip );

				count++;
			}
		}

		keepButtons( count );
	}
	*/
}

//----------------------------------------------------------------------------

void LayoutGroup::keepButtons( int keep )
{
	for(int i=keep;i<childCount();i++)
		((WindowButton *)child(i))->destroy();
}

//----------------------------------------------------------------------------
//EOF
